
<div class="layui-fluid" id="VIEW-CAPITAL" lay-title="入出账管理">

    <!-- 新增账目 -->
    <div class="layui-card" id="capital_add" style="display: none">
            <div class="layui-card-body" style="padding: 15px;">
                <form class="layui-form" action="" id="form_capital_add " lay-filter="capital_add">

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="xing">*</span>摘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;要:</label>
                            <div class="layui-input-inline" >
                                <input type="text"  name="content" placeholder="摘要" lay-verify="required" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="xing">*</span>用途:</label>
                            <div class="layui-input-inline" >
                                <select name="capitalType" id="capitalType" lay-verify="required" lay-filter="capitalTypeFilter">
                                    <option>-请选择-</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="xing">*</span>结算方式:</label>
                            <div class="layui-input-inline" >
                                <select name="accountType" id="accountType" lay-verify="required" lay-filter="accountTypeFilter">
                                    <option>-请选择-</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="xing">*</span>资金渠道:</label>
                            <div class="layui-input-inline" >
                                <select name="source" id="source" lay-verify="required" lay-filter="sourceFilter">
                                    <option >-请选择-</option>
                                </select>
                            </div>
                        </div>

                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="xing">*</span>收入支出:</label>
                            <div class="layui-input-inline" >
                                <select name="inOrOut" >
                                    <option >-请选择-</option>
                                    <option value=false>支出</option>
                                    <option value=true>收入</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="xing">*</span>收支金额:</label>
                            <div class="layui-input-inline" >
                                <input type="text"  id="amountOfMoney" name="amountOfMoney" autocomplete="off" class="layui-input" onkeyup="value=value.replace(/[^\d.]/g,'')" >
                            </div>
                        </div>

                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="xing">*</span>创建时间:</label>
                            <div class="layui-input-inline" >
                                <input type="text" class="layui-input" id="createTime" name="createTime" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><span class="xing">*</span>是否开发票:</label>
                            <div class="layui-input-inline" >
                                <select name="haveBill" >
                                    <option >-请选择-</option>
                                    <option value=false>否</option>
                                    <option value=true>是</option>
                                </select>
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">发票类型:</label>
                            <div class="layui-input-inline" >
                                <select name="billType" id="billType"  lay-filter="billTypeFilter">
                                    <option >-请选择-</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">开票日期:</label>
                            <div class="layui-input-inline" >
                                <input type="text" class="layui-input" id="createBillTime" name="createBillTime" >
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">发票号:</label>
                            <div class="layui-input-inline" >
                                <input type="text"  id="billNo" name="billNo" autocomplete="off" class="layui-input"  >

                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">收票日期:</label>
                            <div class="layui-input-inline" >
                                <input type="text" class="layui-input" id="receiveBillTime" name="receiveBillTime" >
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">开票金额:</label>
                            <div class="layui-input-inline" >
                                <input type="text"  id="billMoney" name="billMoney" autocomplete="off"
                                       class="layui-input" onkeyup="value=value.replace(/[^\d.]/g,'')" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">备&nbsp;&nbsp;注:</label>
                            <div class="layui-input-inline" >
                                <input  name="comment" placeholder="备注" class="layui-input">
                            </div>
                        </div>

                    </div>
<!--
                    <div class="layui-form-item">
                        <label class="layui-form-label">备&nbsp;&nbsp;注:</label>
                        <div class="layui-input-inline" >
                            <textarea  name="comment" placeholder="备注" class="layui-textarea"></textarea>
                        </div>
                    </div>-->
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="form-capital-add-submit">保存</button>
                            <button type="reset" id="reset_add" class="layui-btn layui-btn-primary">清除</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    <!-- 修改账目 -->
    <div class="layui-card" id="capital_edit" style="display: none">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" id="form_capital_edit" lay-filter="capital_edit">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="xing">*</span>摘&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;要:</label>
                        <div class="layui-input-inline" >
                            <input type="hidden" id="hidId" name="financeId">
                            <input type="text" id="content_edit" name="content" placeholder="用途" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="xing">*</span>用途:</label>
                        <div class="layui-input-inline" >
                            <select name="capitalType" id="capitalType_edit" lay-verify="required" lay-filter="capitalTypeFilter">
                                <option>-请选择-</option>
                            </select>
                        </div>
                    </div>

                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="xing">*</span>结算方式:</label>
                        <div class="layui-input-inline" >
                            <select name="accountType" id="accountType_edit" lay-verify="required" lay-filter="accountTypeFilter">
                                <option>-请选择-</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="xing">*</span>资金渠道:</label>
                        <div class="layui-input-inline" >
                            <select name="source" id="source_edit" lay-verify="required" lay-filter="sourceFilter">
                                <option >-请选择-</option>
                            </select>
                        </div>
                    </div>

                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="xing">*</span>收入支出:</label>
                        <div class="layui-input-inline" >
                            <select id="inOrOut_edit" name="inOrOut" >
                                <option >-请选择-</option>
                                <option value=false>支出</option>
                                <option value=true>收入</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="xing">*</span>收支金额:</label>
                        <div class="layui-input-inline" >
                            <input type="text"  id="amountOfMoney_edit" name="amountOfMoney" autocomplete="off" class="layui-input" onkeyup="value=value.replace(/[^\d.]/g,'')" >
                        </div>
                    </div>

                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="xing">*</span>创建时间:</label>
                        <div class="layui-input-inline" >
                            <input type="text" class="layui-input" id="createTime_edit" name="createTime" readonly style="cursor: not-allowed ">
                            <input type="hidden" class="layui-input" id="old_createTime" name="oldCreateTime" >
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label"><span class="xing">*</span>是否开发票:</label>
                        <div class="layui-input-inline" >
                            <select id="haveBill_edit" name="haveBill" >
                                <option >-请选择-</option>
                                <option value=false>否</option>
                                <option value=true>是</option>
                            </select>
                        </div>
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">发票类型:</label>
                        <div class="layui-input-inline" >
                            <select name="billType" id="billType_edit"  lay-filter="billTypeFilter">
                                <option >-请选择-</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">开票日期:</label>
                        <div class="layui-input-inline" >
                            <input type="text" class="layui-input" id="createBillTime_edit" name="createBillTime" >
                        </div>
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">发票号:</label>
                        <div class="layui-input-inline" >
                            <input type="text"  id="billNo_edit" name="billNo" autocomplete="off" class="layui-input"  >

                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">收票日期:</label>
                        <div class="layui-input-inline" >
                            <input type="text" class="layui-input" id="receiveBillTime_edit" name="receiveBillTime" >
                        </div>
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开票金额:</label>
                        <div class="layui-input-inline" >
                            <input type="text"  id="billMoney_edit" name="billMoney" autocomplete="off"
                                   class="layui-input" onkeyup="value=value.replace(/[^\d.]/g,'')" >
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">备&nbsp;&nbsp;注:</label>
                        <div class="layui-input-inline" >
                            <input  name="comment" placeholder="备注" class="layui-input">
                        </div>
                    </div>

                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="form-capital-edit-submit">保存</button>
                        <button type="reset" id="reset_edit" class="layui-btn layui-btn-primary">清除</button>
                    </div>
                </div>
            </form>
        </div>
        </div>

    <!-- 文件上传 -->
    <div class="layui-card" id="capital_upload" style="display: none">
        <form class="layui-form" method="post" action="javascript:;">
            <div class="layui-form-item">
                <div class="layui-upload-drag" style="width: 80%;margin-left: 5%" id="upload">
                    <i class="layui-icon"></i>
                    <p>点击上传，或将文件拖拽到此处</p>
                </div>
                <div class="layui-inline" id="upload_preview"></div>
            </div>
            <div class="layui-form-item layui-hide" id="upload_progress">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline" style="width:21%;">
                    <div class="layui-progress" lay-showpercent="true" lay-filter="upload_progress">
                        <div class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <table id="file_upload" style="width: 88%;margin-left: 5%;" class="layui-table file-list layui-hide">
                    <tr>
                        <td>名称</td>
                        <td>大小</td>
                        <td>状态</td>
                        <td>操作</td>
                    </tr>
                </table>
            </div>
            <div class="layui-form-item">
                <button style="margin-left: 5%;" class="layui-btn all-upload layui-hide">全部上传</button>
            </div>
        </form>
    </div>

    <!-- 查看文件表格-->
    <div class="layui-card" id="capital_files" style="display: none">
        <div class="layui-row">
            <div class="layui-card-body">
                <table id="table_files" class="layui-hide" lay-filter="table_files"></table>
            </div>
        </div>

    </div>

    <!-- 表头条件搜索 -->
    <div class="layui-card">
        <div class="layui-card-header">
            <i class="layui-icon layui-icon-cluster"></i>&nbsp;入出账管理
        </div>
        <div class="layui-row">
            <div class="layui-card-body">


                <table id="capital-table" class="layui-hide" lay-filter="capital-table"></table>
            </div>
        </div>
    </div>

    <script type="text/html" id="capitalTool_bar">
        <button class="layui-btn layui-btn-sm" style="background-color: #00d57b;font-size:14px;" lay-event="add">新增</button>
        <button class="layui-btn layui-btn-sm" lay-event="edit">信息修改</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</button>
    </script>

</div>
<script>
    layui.use(['jquery','admin', 'table', 'form', 'dropdown', 'laydate','upload',"element","fileDownloadHelper"],
        function ($,admin, table, form, dropdown,element, upload) {
        var $ = layui.$,
            laydate = layui.laydate,
            form = layui.form,
            admin = layui.admin,
            upload = layui.upload,
            element = layui.element,
            fileDownloadHelper = layui.fileDownloadHelper,
            index;
        layer.ready(function () {
            setTimeout(function(){
               setColor();
            },300);
        });
        //渲染数据字典下拉 {事项类型  资金渠道   账户类型  发票类型}
        admin.get({
            api: "getDictValue",
            data:{
                "dictCode" : "capitalType",
            },
            //请求成功
            success:function(res){
                $.each(res.data, function (index, item) {
                    $('#capitalType').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                    $('#capitalType_edit').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                    $('#capitalType_find').append(new Option(item.key, item.value));// 下拉菜单里添加元素

                });
                //重新渲染 固定写法
                layui.form.render("select");
            }
        });
            admin.get({
                api: "getDictValue",
                data:{
                    "dictCode" : "settlementSource",
                },
                //请求成功
                success:function(res){
                    $.each(res.data, function (index, item) {
                        $('#source').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                        $('#source_edit').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                        $('#source_find').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                    });
                    //重新渲染 固定写法
                    layui.form.render("select");
                }
            });
            admin.get({
                api: "getDictValue",
                data:{
                    "dictCode" : "accountType",
                },
                //请求成功
                success:function(res){
                    $.each(res.data, function (index, item) {
                        $('#accountType').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                        $('#accountType_edit').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                        $('#accountType_find').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                    });
                    //重新渲染 固定写法
                    layui.form.render("select");
                }
            });
            admin.get({
                api: "getDictValue",
                data:{
                    "dictCode" : "billType",
                },
                //请求成功
                success:function(res){
                    $.each(res.data, function (index, item) {
                        $('#billType').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                        $('#billType_edit').append(new Option(item.key, item.value));// 下拉菜单里添加元素
                    });
                    //重新渲染 固定写法
                    layui.form.render("select");
                }
            });

            //入出账票据查看表格
            var filetable = table.render({
                elem: '#table_files'
                ,api: 'getAllFiles' //数据接口
                ,title: '入出账票据'
                ,limit: 5
                ,limits:[5,10,15]
                ,page: true //开启分页
                ,even: true //开启隔行背景
                ,parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.message, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.records //解析数据列表
                    };
                }

                ,cols: [[ //表头
                    {field: 'fileId', width: 0},
                    {field: 'financeId', width: 0},
                    { title: '文件名', field: 'fileName', width: 280},
                    { title: '文件大小', field: 'fileSize', width: 100},
                    { title: '上传时间', field: 'createTime', width: 150 ,templet: function(d){
                            if(d.createTime!=null){
                                return (d.createTime).replace("T"," ");
                            }else{
                                return "";
                            }
                        },},
                    { title: '上传人', field: 'createName', width: 110 },
                    {templet: fileComplain,  fixed: "right",width: 150 ,title: '操作'}

                ]],done: function(res, curr, count){
                    $("[data-field='financeId']").css('display','none');
                    $("[data-field='fileId']").css('display','none');

                }
            });
            function fileComplain(d){//操作中显示的内容
                return [
                    '<a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="downloadFile"><i class="layui-icon">&#xe601;</i>下载</a>',
                    '<a class="layui-btn layui-btn-xs layui-btn-danger"  lay-event="delFile"><i class="layui-icon">&#xe640;</i>删除</a>',
                ].join('');
            }

            //入出账票据表格侧边工具条
            table.on('tool(table_files)', function (obj) {
                var data = obj.data;
                if(obj.event === 'delFile') {
                    layer.confirm('是否删除文件：'+data.fileName+'？', {
                        btn: ['确认','取消'] //按钮
                    }, function(){
                        admin.delete({
                            api: "delFiles",
                            data: {
                                fileId:data.fileId
                            },
                            success: function(res) {
                                table.reload('table_files', {
                                    page: {
                                        curr: 1 //重新从第 1 页开始
                                    },where:{
                                        busiId:data.financeId
                                    }
                                });
                            }

                        });
                    });

                }
                else if(obj.event === 'downloadFile') {
                    t = {
                        api: "uploadFileDownload",
                        data: {
                            id:data.fileId
                        }
                    };
                    fileDownloadHelper.downloadFile(t);

                }

            });

            var uploadInst;

            function fileUpload(busiId) {
                var files;
                uploadInst = upload.render({
                    elem : '#upload',
                    url : 'api/v1/file/upload',
                    data: {
                        "busiId"  : busiId
                    },
                    accept : 'file',
                    size : 1024 * 8,
                    auto : false,
                    bindAction : ".all-upload",
                    multiple : true,
                    choose : function(obj) {
                        files = obj.pushFile();
                        $(".file-list").removeClass("layui-hide");
                        $(".all-upload").removeClass("layui-hide");
                        obj.preview(function(index, file, result) {
                            var tr = $([ "<tr id='upload-" + index + "'>",
                                "<td>" + file.name + "</td>",
                                "<td>" + (file.size / 1024).toFixed(1) + "KB</td>",
                                "<td>等待上传</td>",
                                "<td>",
                                "<button class='layui-btn layui-mini file-reload layui-hide'>重新上传</button>",
                                "<button class='layui-btn layui-mini layui-btn-danger file-del'>删除</button>",
                                "</td>",
                                "</tr>" ].join(""));

                            tr.find(".file-reload").on("click", function() {
                                obj.upload(index, file);
                            })

                            tr.find(".file-del").on("click", function() {
                                delete files[index];
                                tr.remove();
                            })

                            $("#file_upload").append(tr);
                        });
                    },
                    allDone : function(obj) { //当文件全部被提交后，才触发
                        console.log(obj.total); //得到总文件数
                        console.log(obj.successful); //请求成功的文件数
                        console.log(obj.aborted); //请求失败的文件数
                    },
                    done : function(res, index, upload) { //上传后的回调
                        if (res.code == 2000) { //上传成功
                            var tr = $("#file_upload").find('tr#upload-' + index),
                                tds = tr.children();
                            tds.eq(2).html("<span style='color:#5FB878;'>上传成功</span>")
                            tds.eq(3).html(""); //清空操作
                            delete files[index];
                            return;
                        }
                    },
                    error : function(index, upload) {
                        var tr = $("#file_upload").find('tr#upload-' + index),
                            tds = tr.children();
                        tds.eq(2).html("<span style='color:#FF5722;'>上传失败</span>")
                        tds.eq(3).find(".file-reload").removeClass("layui-hide"); //清空操作
                    }
                })
            }



        /* 监听修改提交 */
        form.on('submit(form-capital-edit-submit)', function (data) {
            admin.put({
                api: "capitalEdit",
                data:data.field,
                //请求成功
                success:function(res){
                    layer.close(index);
                    layer.msg(res.msg);
                    table.reload('capital-table', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                    setTimeout(function(){
                        setColor();
                    },300);
                }
            });
            return false;
        });

        /* 监听提交 */
        form.on('submit(form-capital-add-submit)', function (data) {
            admin.post({
                api: "capitalAdd",
                data:data.field,
                //请求成功
                success:function(res){
                    layer.close(index);
                    $("#reset_add").click();
                    layer.msg(res.msg);
                    table.reload('capital-table', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                    setTimeout(function(){
                        setColor();
                    },300);
                }
            });
            return false;
        });

        table.render({
            elem: '#capital-table'
            ,height: 'full-165'
            ,api: 'getAllCapitalDetail' //数据接口
            ,title: '资金明细查询'
            ,page: true //开启分页
            ,even: false //开启隔行背景
            ,toolbar:'#capitalTool_bar'
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.records //解析数据列表
                };
            }

            ,cols: [[ //表头
                { title: '', type: 'checkbox', fixed: true, width: 60 },

                {field: 'financeId', width: 0},
                { title: '创建时间',field: 'createTime',fixed: true, width: 150 ,templet: function(d){
                        return (d.createTime).replace("T"," ");
                    },},
                { title: '摘要', field: 'content',fixed: true, width: 300},
                { field: 'capitalType', width: 0},
                { field: 'fileId', width: 0},
                { title: '用途', field: 'capitalTypeToString', width: 90},
                { title: '收入/支出', field: 'inOrOut', width: 90,templet: function(d){
                        if(d.inOrOut){
                            return "<span class=\"layui-badge layui-bg-green\">收入</span>";
                        }else{
                            return  "<span class=\"layui-badge layui-bg-orange\">支出</span>";
                        }
                    }},
                { title: '收/支金额(元)', field: 'amountOfMoney', width: 120,templet: function(d){
                        if(d.inOrOut){
                            return d.amountOfMoney;
                        }else{
                            return  Math.abs(d.amountOfMoney);
                        }
                    }},
                { field: 'accountType', width: 0 },
                { title: '结算方式', field: 'accountTypeToString', width: 80 ,templet: function(d){
                        if(d.accountTypeToString=="公帐"){
                            return "<span class=\"layui-badge layui-bg-green\">公帐</span>";
                        }else if(d.accountTypeToString=="私帐"){
                            return  "<span class=\"layui-badge layui-bg-blue\">私帐</span>";
                        }else if(d.accountTypeToString=="现金"){
                            return  "<span class=\"layui-badge\">现金</span>";
                        }
                    }},
                {field: 'source', width: 0 },
                { title: '资金渠道', field: 'sourceToString', width: 110 },
                { title: '渠道结余资金(元)', field: 'surplus', width: 150 },

                { title: '是否开发票', field: 'haveBill', width: 120 ,templet: function(d){
                        if(d.haveBill){
                            return "<span class=\"layui-badge layui-bg-green\">是</span>";
                        }else{
                            return  "<span class=\"layui-badge layui-bg-red\">否</span>";
                        }
                    }},
                {field: 'billType', width: 0 },
                { title: '发票类型', field: 'billTypeToString', width: 150 },
                { title: '开票日期', field: 'createBillTime', width: 150 ,templet: function(d){
                        if(d.createBillTime!=null){
                            return (d.createBillTime).replace("T"," ");
                        }else{
                            return " ";
                        }

                    },},
                { title: '收票日期', field: 'receiveBillTime', width: 150 ,templet: function(d){
                        if(d.receiveBillTime!=null){
                            return (d.receiveBillTime).replace("T"," ");
                        }else{
                            return " ";
                        }
                    },},
                { title: '发票号', field: 'billNo', width: 150 },
                { title: '开票金额(元)', field: 'billMoney', width: 150 },

                { title: '备注', field: 'comment', minWidth: 130},
                { title: '创建人',field: 'createName', width: 130 },
                { title: '修改时间', field: 'modifyTime', width: 150 ,templet: function(d){
                        if(d.modifyTime!=null){
                            return (d.modifyTime).replace("T"," ");
                        }else{
                            return "";
                        }
                    },},
                { title: '修改人', field: 'updateName', width: 100 },
                {templet: complain,  fixed: "right",width: 180 ,title: '操作'}

            ]],done: function(res, curr, count){
                $("[data-field='financeId']").css('display','none');
                $("[data-field='fileId']").css('display','none');
                $("[data-field='capitalType']").css('display','none');
                $("[data-field='accountType']").css('display','none');
                $("[data-field='source']").css('display','none');
                $("[data-field='billType']").css('display','none');


            }
        });
        function setColor(){
            $(".layui-table").each(function(){
                $(this).find("tr").each(function () {
                    var open = $(this).find('td[data-field="haveBill"]').attr('data-content');
                    if(open=="false"){   //给状态为false的数据行设置背景色
                        $(this).css('background',"#fff000");
                    }
                });
            })

        }
        function complain(d){//操作中显示的内容
            return [
                '<a class="layui-btn layui-btn-xs" style="background-color: #00d57b;" lay-event="reUpload"><i class="layui-icon">&#xe62f;</i>票据上传</a>',
                '<a class="layui-btn layui-btn-xs layui-btn-xs" lay-event="file_detail"><i class="layui-icon layui-icon-search"></i><!--<i class="layui-icon">&#xe601;</i>-->查看</a>',
            ].join('');
        }

        var $ = layui.$, active = {
            reload: function(){

                //执行重载
                table.reload('capital-table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        customerID: $('#customerID').val(),
                        customerName: $('#customer_sel_name').val(),
                        area: $('#area_sel').val(),
                        meterID:$('#meterID').val(),
                        address:$('#place').val(),
                        organization:$('#organization').val()
                    }
                }, 'data');
                setTimeout(function(){
                    setColor();
                },300);
            }
        };
        $('#search').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        //头工具栏事件
        table.on('toolbar(capital-table)', function(obj){
            //新增入出账数据
            if(obj.event === 'add'){
                index = layer.open({
                    type: 1
                    ,anim: 5
                    ,shade: 0
                    ,maxmin: false
                    ,area:'800px'
                    ,title:'新增数据'
                    ,content: $('#capital_add')
                });
            }
            //删除入出账数据
            if(obj.event === 'del'){
                var checkStatus = table.checkStatus(obj.config.id);
                var rows = checkStatus.data.length;
                if(rows == 0){
                    layer.msg("请至少选择一条数据！");
                    return false;
                }
                var id = checkStatus.data[0].financeId;
                if(rows > 1){
                    for (var i = 1; i <rows ; i++) {
                        id += ","+checkStatus.data[i].financeId;
                    }
                }
                layer.confirm('是否删除当前选中 '+rows+' 条数据？', {
                    btn: ['确认','取消'] //按钮
                }, function(){
                    admin.delete({
                        api: "capitalDel",
                        data:{"delId":id },
                        success: function(res) {
                            table.reload('capital-table', {
                                page: {
                                    curr: 1 //重新从第 1 页开始
                                }
                            });
                            setTimeout(function(){
                                setColor();
                            },300);
                        }
                    });
                })

            }
            //编辑收支记录
            if(obj.event === 'edit'){
                var checkStatus = table.checkStatus(obj.config.id);
                var rows = checkStatus.data.length;
                if(rows != 1){
                    layer.msg("必须且只能选择一条数据！");
                    return false;
                }
                var data = checkStatus.data[0];
                var tips="";

                index = layer.open({
                    type: 1
                    ,anim: 5
                    ,shade: 0
                    ,maxmin: false
                    ,area:'800px'
                    ,title:'修改数据'
                    ,content: $('#capital_edit')
                });

                $("#hidId").val(data.financeId);

                $("#content_edit").val(data.content);

                var capitalType = 'dd[lay-value=' + data.capitalType + ']';
                $('#capitalType_edit').siblings("div.layui-form-select").find('dl').find(capitalType).click();

                var accountType = 'dd[lay-value=' + data.accountType + ']';
                $('#accountType_edit').siblings("div.layui-form-select").find('dl').find(accountType).click();

                var source = 'dd[lay-value=' + data.source + ']';
                $('#source_edit').siblings("div.layui-form-select").find('dl').find(source).click();

                var inOrOut = 'dd[lay-value=' + data.inOrOut + ']';
                $('#inOrOut_edit').siblings("div.layui-form-select").find('dl').find(inOrOut).click();

                $("#amountOfMoney_edit").val(data.amountOfMoney);

                $("#createTime_edit").val(data.createTime.replace("T"," "));




                var haveBill = 'dd[lay-value=' + data.haveBill + ']';
                $('#haveBill_edit').siblings("div.layui-form-select").find('dl').find(haveBill).click();

                var billType;
                var billType_edit;
                if(data.billType==null){
                    billType_edit = "-请选择- ";
                }else{
                    billType_edit = data.billType
                }
                billType= 'dd[lay-value=' + billType_edit + ']';
                $('#billType_edit').siblings("div.layui-form-select").find('dl').find(billType).click();

                $("#billNo_edit").val(data.billNo);
                $("#billMoney_edit").val(data.billMoney);

                if(data.createBillTime==null){
                    $("#createBillTime_edit").val("");
                }else{
                    $("#createBillTime_edit").val(data.createBillTime.replace("T"," "));
                }

                if(data.receiveBillTime==null){
                    $("#receiveBillTime_edit").val("");
                }else{
                    $("#receiveBillTime_edit").val(data.receiveBillTime.replace("T"," "));
                }

                $("#old_createTime").val(data.createTime.replace("T"," "));

                $("#comment_edit").val(data.comment);
            }
        });


        //侧边工具条
        table.on('tool(capital-table)', function (obj) {
            var data = obj.data;
            uploadInst=null;
            fileUpload(data.financeId);

            //上传入出账票据
            if(obj.event === 'reUpload'){
                index = layer.open({
                    type: 1
                    ,maxmin: false
                    ,area:'800px'
                    ,title:'上传入出账票据'
                    ,content: $('#capital_upload')
                    ,success:function (layero) {
                        var mask = $(".layui-layer-shade");
                        mask.appendTo(layero.parent());
                    }
                    ,cancel:function () {
                        window.location.reload();
                    }

                });
            }
            else if(obj.event === 'file_detail') {
                table.reload('table_files', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },where:{
                        busiId:data.financeId
                    }
                });
                index = layer.open({
                    type: 1
                    , anim: 5
                    , shade: 0
                    , maxmin: false
                    , area: '800px'
                    , title: '当前记录所有票据'
                    , content: $('#capital_files')
                });

            }

        });

            form.render();

            //日期时间选择器
            laydate.render({
                elem: '#createTime'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#createBillTime'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#receiveBillTime'
                ,type: 'datetime'
            });
            //暂时屏蔽修改创建时间
            /*laydate.render({
                elem: '#createTime_edit'
                ,type: 'datetime'
            });*/
            laydate.render({
                elem: '#createTime_find'
                ,type: 'datetime'
                ,range: true
            });
            laydate.render({
                elem: '#createBillTime_edit'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#receiveBillTime_edit'
                ,type: 'datetime'
            });
    })
</script>